package com.vitabuybuy.tv.ui.mine.talent.viewmodel

import android.view.View
import androidx.lifecycle.MutableLiveData
import com.vitabuybuy.tv.dto.FieldLabelDto
import com.vitabuybuy.tv.dto.TalentUserInfoDto
import com.library.common.base.BaseViewModel
import com.library.common.base.MessageModel
import com.library.common.ext.rxHttpRequest
import com.library.common.net.error.msg
import com.library.common.net.loadingtype.LoadingType
import com.library.common.toast.XToast
import com.library.common.util.JsonUtil
import com.vitabuybuy.tv.network.AddressRepository
import com.vitabuybuy.tv.network.ApplyTalentRepository
import com.vitabuybuy.tv.network.AuthRepository
import java.util.HashMap

class TalentApplyViewModel : BaseViewModel() {

    fun getRegionList(regionId: Int?) {
        rxHttpRequest {
            onRequest = {
                val it = AddressRepository.getRegionList(regionId).await()
                defUI.msgEvent.postValue(MessageModel(1, obj = it))
            }
            onError = {
                XToast.normal(it.msg)
            }
            isShowDialogRequest = true
        }
    }

    val labellist = MutableLiveData<MutableList<FieldLabelDto>>()
    fun getFieldLabelList() {
        rxHttpRequest {
            onRequest = {
                labellist.value = ApplyTalentRepository.getFieldLabelList().await()
                statusView.set(LoadingType.SHOW_CONTENT)
            }
            onError = {
                XToast.normal(it.msg)
            }
            isLoadingType = true
            isRefresh = true
        }
    }

    fun uploadImage(path: String, position: Int) {
        rxHttpRequest {
            onRequest = {
                val it = AuthRepository.upLoadImage(path).await()
                defUI.msgEvent.postValue(MessageModel(2, obj = it, arg1 = position))
            }
            onError = {
                XToast.normal(it.msg)
            }
            isShowDialogRequest = true
        }
    }

    fun applyTalent(params: HashMap<String, Any>) {
        rxHttpRequest {
            onRequest = {
                ApplyTalentRepository.applyTalent(params).await()
                defUI.msgEvent.postValue(MessageModel(3))
            }
            onError = {
                XToast.normal(it.msg)
            }
            isShowDialogRequest = true
        }
    }

    val applyTalentUserInfo = MutableLiveData<TalentUserInfoDto>()

    fun getTalentUserInfo() {
        rxHttpRequest {
            onRequest = {
                applyTalentUserInfo.value = ApplyTalentRepository.applyTalentUserInfo().await()
            }
            onError = {
                XToast.normal(it.msg)
            }
            isShowDialogRequest = true
        }
    }
}
